package codetop.bytedance.T209;

/**
 * @Author: 18362
 * @Create: 2022-09-17 21:11:23 星期六
 */
class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int left = 0, right = 0, sum = 0, minLen = Integer.MAX_VALUE;
        while (right < nums.length) {
            int num = nums[right++];
            sum += num;
            while (sum >= target) {
                minLen = Math.min(minLen, right - left);
                int n = nums[left++];
                sum -= n;
            }
        }
        return minLen == Integer.MAX_VALUE ? 0 : minLen;
    }
}